package com.neuralnoise.hibernate.twitter;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.MappedSuperclass;

@MappedSuperclass
public abstract class AbstractScreen implements java.io.Serializable {

	private static final long serialVersionUID = -8493367700789406433L;

	private Long id;

	private Set<Screen> screensForSubject = new HashSet<Screen>(0);
	private Set<Screen> screensForObject = new HashSet<Screen>(0);

	public AbstractScreen() { }
	
	public AbstractScreen(long id) {
		this.id = id;
	}

	public AbstractScreen(Long id, Set<Screen> screensForSubject, Set<Screen> screensForObject) {
		this(id);
		this.screensForSubject = screensForSubject;
		this.screensForObject = screensForObject;
	}

	@Id
	@Column(name = "id", unique = true, nullable = false)
	public Long getId() {
		return this.id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "screensForObject")
	public Set<Screen> getScreensForSubject() {
		return this.screensForSubject;
	}

	public void setScreensForSubject(Set<Screen> screensForSubject) {
		this.screensForSubject = screensForSubject;
	}

	@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@JoinTable(name = "TwitterFriendOf", joinColumns = { @JoinColumn(name = "subject", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "object", nullable = false, updatable = false) })
	public Set<Screen> getScreensForObject() {
		return this.screensForObject;
	}

	public void setScreensForObject(Set<Screen> screensForObject) {
		this.screensForObject = screensForObject;
	}

}
